﻿using Extention.ENode.Rpc.Runtime.Communally.Entitys.Messages;
using Extention.ENode.Rpc.Transport.Codec;
using DotNetty.Buffers;

namespace Extention.ENode.Rpc.Transport.Impl
{
    /// <summary>
    /// 基于DotNetty的消息发送者基类
    /// </summary>
    public abstract class DefaultDotNettyMessageSender
    {
        private readonly ITransportMessageEncoder _transportMessageEncoder;

        protected DefaultDotNettyMessageSender(ITransportMessageEncoder transportMessageEncoder)
        {
            _transportMessageEncoder = transportMessageEncoder;
        }

        protected IByteBuffer GetByteBuffer(TransportMessage message)
        {
            var data = _transportMessageEncoder.Encode(message);
            //var buffer = PooledByteBufferAllocator.Default.Buffer();
            return Unpooled.WrappedBuffer(data);
        }


    }
}